# admin_routes.py
from fastapi import APIRouter, FastAPI
from admin.user_api import UserApi
from admin.user_role_api import UserRoleApi
from admin.user_permission_api import UserPermissionApi
from admin.menu_api import MenuApi
from admin.upload_api import UploadApi
from admin.sys_admin_api import SysAdminApi
from admin.sys_role_api import SysRoleApi

class RouteManager:

    def __init__(self):
        self.router = APIRouter()

    def setup_user_routes(self):
        # 用户路由
        user_api = UserApi()
        self.router.add_api_route(
            "/admin/user/add",  # 添加用户
            user_api.user_register,
            methods=["POST"],
        )
        self.router.add_api_route(
            "/admin/user/login",  # 用户登录
            user_api.user_login,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/user/list",  # 用户列表
            user_api.user_list,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/user/info",  # 用户信息
            user_api.user_info,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/user/detail",  # 用户详情
            user_api.user_detail,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/user/del",  # 删除用户
            user_api.user_delete,
            methods=["GET"]
        )

    def setup_role_routes(self):
        # 角色路由
        role_api = UserRoleApi()
        self.router.add_api_route(
            "/admin/role/list",  # 角色列表
            role_api.list_user_roles,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/role/detail",  # 角色详情
            role_api.detail_user_role,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/role/add",  # 添加角色
            role_api.create_user_role,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/role/del",  # 删除角色
            role_api.delete_user_role,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/role/update",  # 更新角色
            role_api.update_user_role,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/role/bind/permission",  # 角色绑定权限
            role_api.assign_permissions_to_role,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/role/bind/user",  # 角色绑定用户
            role_api.assign_user_to_role,
            methods=["POST"]
        )

    def setup_permission_routes(self):
        # 权限路由
        permission_api = UserPermissionApi()
        self.router.add_api_route(
            "/admin/permission/list",  # 权限列表
            permission_api.list_user_permissions,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/permission/detail",  # 权限详情
            permission_api.detail_user_permission,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/permission/add",  # 添加权限
            permission_api.create_user_permission,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/permission/del",  # 删除权限
            permission_api.delete_user_permission,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/permission/update",  # 更新权限
            permission_api.update_user_permission,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/permission/menu",
            permission_api.update_permission_menu,
            methods=["POST"]
        )

    def setup_menu_routes(self):
        # 菜单路由
        menu_api = MenuApi()
        self.router.add_api_route(
            "/admin/menu/create",  # 创建菜单
            menu_api.create_menu,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/menu/list",  # 菜单列表
            menu_api.menu_list,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/menu/detail",  # 菜单详情
            menu_api.menu_detail,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/menu/update",  # 更新菜单
            menu_api.update_menu,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/menu/user",  # 用户菜单
            menu_api.user_menu,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/menu/delete",  # 删除菜单
            menu_api.delete_menu,
            methods=["GET"]
        )

    def setup_upload_routes(self):
        # 用户路由
        upload_api = UploadApi()
        self.router.add_api_route(
            "/admin/upload/image",  # 用户信息
            upload_api.upload_image,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/image/detail",  # 图片详情
            upload_api.upload_detail,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/image/list",  # 图片列表
            upload_api.image_list,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/image/delete",  # 删除图片
            upload_api.upload_delete,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/file/upload",  # 上传文件
            upload_api.upload_file,
            methods=["POST"]
        )

    def setup_sys_user_routes(self):
        # 系统管理员路由
        sys_admin_api = SysAdminApi()
        self.router.add_api_route(
            "/admin/sys/user/list",
            sys_admin_api.sys_admin_list,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/sys/user/login",  # 系统管理员登录
            sys_admin_api.sys_login,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/sys/user/create",  # 创建系统管理员
            sys_admin_api.sys_create_user,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/sys/user/update",  # 更新系统管理员
            sys_admin_api.sys_update_user,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/sys/user/delete",  # 删除系统管理员
            sys_admin_api.sys_delete_user,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/sys/user/detail",  # 系统管理员详情
            sys_admin_api.sys_detail_user,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/sys/user/info",  # 系统管理员信息
            sys_admin_api.sys_user_info,
            methods=["GET"]
        )

    def setup_sys_role_routes(self):
        sys_role_api = SysRoleApi()
        self.router.add_api_route(
            "/admin/sys/role/list",  # 系统角色列表
            sys_role_api.lists,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/sys/role/detail",  # 系统角色详情
            sys_role_api.detail,
            methods=["GET"]
        )
        self.router.add_api_route(
            "/admin/sys/role/create",  # 创建系统角色
            sys_role_api.create,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/sys/role/update",  # 更新系统角色
            sys_role_api.update,
            methods=["POST"]
        )
        self.router.add_api_route(
            "/admin/sys/role/delete",  # 删除系统角色
            sys_role_api.delete,
            methods=["GET"]
        )
    def get_router(self):
        # 这里可以继续添加其他控制器的路由设置
        self.setup_user_routes()  # 管理员路由
        self.setup_role_routes()  # 角色路由
        self.setup_permission_routes()  # 权限路由
        self.setup_menu_routes()  # 菜单路由
        self.setup_upload_routes()  # 上传路由
        self.setup_sys_user_routes()  # 系统管理员路由
        self.setup_sys_role_routes() # sys角色路由
        return self.router
